package com.sann.eduservice.controller;


import com.sann.common.utils.R;
import com.sann.eduservice.entity.subject.vo.OneSubject;
import com.sann.eduservice.service.SubjectService;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 *
 * @author zjw
 * @since 2021-04-14
 */
@Api(tags="课程分类管理")
@RestController
@RequestMapping("/eduservice/subject")
@CrossOrigin //跨域
@Slf4j
public class SubjectController {

    @Autowired
    private SubjectService subjectService;

    /**
     * 导入课程分类
     * @param file 获取上传过来文件，把文件内容读取出来
     * @return
     */
    @ApiOperation(value = "导入课程分类")
    @PostMapping(value = "importSubject")
    public R importSubject(MultipartFile file){
        log.info("开始导入......");
        //上传过来excel文件
        subjectService.importSubject(file, subjectService);
        return R.ok();
    }

    /**
     * 获取所有课程科目，并以树形结构返回（课程科目最多只有二级分类，后面权限会有递归写法）
     * @return
     */
    @ApiOperation(value = "获取所有课程科目(树形)")
    @GetMapping(value = "getAllSubjectTree")
    public R getAllSubjectTree(){
        //list集合泛型是一级分类
        List<OneSubject> treeList = subjectService.getAllOneTwoSubjectTree();
        return R.ok().data("tree", treeList);
    }

}

